package models

import (
	"fmt"
	"github.com/go-redis/redis"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"weekFirst/global"
)

var err error

func InitMySQL() {
	dsn := "root:root@tcp(127.0.0.1:3306)/weekone?charset=utf8mb4&parseTime=True&loc=Local"
	global.Db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})

	fmt.Println("MySQL 连接成功")

	global.Db.AutoMigrate(new(User), new(Friend))
}

var RedisClient *redis.Client

func InitRedis() {
	RedisClient = redis.NewClient(&redis.Options{
		Addr:     "localhost:6379",
		Password: "", // no password set
		DB:       0,  // use default DB
	})

	pong, err := RedisClient.Ping().Result()
	fmt.Println(pong, err)
	// Output: PONG <nil>
}
